<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html 
	xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://xmlns.jcp.org/jsf/html"
	xmlns:p="http://primefaces.org/ui"
	xmlns:f="http://java.sun.com/jsf/core"
	>
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<h:title>DataTable Test</h:title>
<script>
	function showUser(){
		window.location.href="login.jsf";
	}
</script>
	
</h:head>
<h:body>
	Hello world<h:inputText value="${USER.username}"></h:inputText><br/>
	<a href="javascript:showUser()">跳转</a>
	<h:form>
		<p:commandButton value="退出" action="#{userController.logout()}"></p:commandButton>
		
		<p:dataTable id="listuser" var="users" paginator="true"  value="#{userController.userList}"
		sortMode="multiple" rendered="true" rows="5" >
			<f:facet name="header">
				<p:commandButton value="more" id="more"  style="float:right" icon="ui-icon-calculator"/>
				
				<p:columnToggler datasource="listuser" trigger="more">
				<!--直接读取列头标题名 用于选择 需要显示的列 -->
				</p:columnToggler>
			</f:facet>
			<p:column sortBy="#{users.id}"><!--排序方式-->
				<f:facet name="header">ID</f:facet><!--列头标题名  等同column中的headerText 。。。 -->
				#{users.id}
				<f:facet name="footer">ID footer</f:facet>				
			</p:column>
			<p:column headerText="用户名" footerText="用户名 footer"><!--列头标题名   -->
				#{users.username}
			</p:column>
			
			<p:column headerText="密码" footerText="密码 footer"><!--列头标题名   -->
				#{users.password}
			</p:column>
			
			<p:column headerText="添加时间" footerText="添加时间 footer " sortBy="#{users.addtime}">
				<h:outputText value="#{users.addtime}">
					<f:convertDateTime timeZone="GMT+8" pattern="yyyy-MM-dd HH:mm:ss"></f:convertDateTime>
				</h:outputText>
			</p:column>
			
			<p:column headerText="操作" footerText="操作 footer ">
				<p:commandLink value="delete" onclick="PF('cd').show()"/>
				
				<p:commandLink value="modify" action="#{userController.showUser(users)}"/>
					
				<p:confirmDialog message="Be sure to delete this data？" widgetVar="cd">
					<p:commandLink value="delete" actionListener="#{userController.deleteById(users)}" update="@all" oncomplete="PF('cd').hide()" style="margin-left:35px"/>
					<p:commandLink value="cancel" onclick="PF('cd').hide()" style="margin-left:80px"/>
				</p:confirmDialog>
			</p:column>
			
		</p:dataTable>
		<!-- 
		<p:dialog header="Header Text" widgetVar="dlg">//Content</p:dialog>
		<p:commandButton value="Show" type="button" onclick="PF('dlg').show()" />
		<p:commandButton value="Hide" type="button" onclick="PF('dlg').hide()" />
		-->
	</h:form>
</h:body>
</html>